// 模拟火车票订单数据
const orders = [
    { id: '12345', from: '北京', to: '上海', date: '2024-12-25', time: '08:00', status: 'completed', price: '553元' },
    { id: '23456', from: '广州', to: '深圳', date: '2024-12-26', time: '14:30', status: 'pending', price: '120元' },
    { id: '34567', from: '成都', to: '重庆', date: '2024-12-27', time: '09:15', status: 'completed', price: '150元' },
    { id: '45678', from: '南京', to: '杭州', date: '2024-12-28', time: '16:45', status: 'cancelled', price: '180元' },
];

// 动态生成订单列表
function displayOrders(filteredOrders = orders) {
    const orderList = document.getElementById('orderList');
    const orderCount = document.getElementById('orderCount');
    orderList.innerHTML = '';

    if (filteredOrders.length === 0) {
        orderList.innerHTML = '<li class="order-item">未找到符合条件的订单。</li>';
        orderCount.textContent = 0;
        return;
    }


    filteredOrders.forEach(order => {
        const listItem = document.createElement('li');
        listItem.classList.add('order-item');
        listItem.innerHTML = `
            <div class="order-header">
                <span class="order-id">订单号：${order.id}</span>
                <span class="order-status ${order.status}">
                    ${getStatusText(order.status)}
                </span>
            </div>
            <div class="order-details">
                <p><strong>出发地：</strong>${order.from}</p>
                <p><strong>目的地：</strong>${order.to}</p>
                <p><strong>日期：</strong>${order.date}</p>
                <p><strong>时间：</strong>${order.time}</p>
                <p><strong>票价：</strong>${order.price}</p>
            </div>
        `;
        orderList.appendChild(listItem);
    });

    // 更新订单数量
    orderCount.textContent = filteredOrders.length;
}

// 搜索订单
function searchOrders() {
    const searchInput = document.getElementById('searchInput').value.trim();
    const filteredOrders = orders.filter(order =>
        order.id.includes(searchInput) ||
        order.from.includes(searchInput) ||
        order.to.includes(searchInput)
    );
    displayOrders(filteredOrders);
}

// 获取状态文字
function getStatusText(status) {
    switch (status) {
        case 'completed': return '已完成';
        case 'pending': return '待支付';
        case 'cancelled': return '已取消';
        default: return '未知状态';
    }
}

// 初始化显示所有订单
displayOrders();

